package com.leetcode.day7_31;

import java.util.Map;

/**
 * author: the_ring
 * Time: 2021/7/31 17:01
 * log: 按公因数计算最大组件大小
 * link: https://leetcode-cn.com/problems/largest-component-size-by-common-factor/
 */
public class Day2Code2 {
    public static void main(String[] args) {
        int[] test = new int[]{4, 6, 15, 35};
        Solution2 solution = new Solution2();
        int result = solution.largestComponentSize(test);
        System.out.println(result);
    }
}

class Solution2 {

    public int largestComponentSize(int[] nums) {
        int length = nums.length;
        int[][] table = new int[length][length];
        for (int i = 0; i < length; i++) {
            for (int j = i + 1; j < length; j++) {
                if (factor(nums[i], nums[j])) {
                    table[i][j] = 1;
                    table[j][i] = 1;
                }
            }
        }
        int max = 0;
        int counter = 0;
        int[] tag = new int[length];
        for (int i = 0; i < length; i++) {
            if (table[i].equals(1))
                System.out.println("True");;
        }
        return 0;
    }

    public boolean factor(int a, int b) {
        int sub = Math.abs(a - b);
        while (sub != 0) {
            if (a > b) b = sub;
            else a = sub;
            sub = Math.abs(a - b);
        }
        if (a == 1) return true;
        else return false;
    }
}

